package com.sms.project;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.sms.DB.OperateDB;

/*
 * 项目汇报
 */
public class PReport {
	private int prID;// 汇报编号
	private String type;
	private int taskID;// 项目编号
	private int rootid;
	private int pid;
	private String isleaf;
	private String fromID;
	private String fromName;
	private String sname;// 汇报人的姓名
	// private String toID;
	// private String toName;
	private String prTime;
	private String content;
	private String presult;
	private String isAppend;
	private int grade;
	private List<Map> appendFile = null;// 项目附件
	private List<String> toName = null;// 接受者名字
	private List<String> toID = null;// 接受者ID

	public void init(Map map, int grade) {
		this.setPrID((Integer) map.get("t_reportid"));
		this.setType(map.get("tr_type").toString());
		System.out.println("ddd1" + (Integer)map.get("taskid"));
		this.setTaskID((Integer)map.get("taskid"));
		this.setRootid((Integer)map.get("rootid"));
		this.setPid((Integer) map.get("pid"));
		this.setIsleaf(map.get("isleaf").toString());
		this.setFromID(map.get("fromid").toString());
		this.setFromName(map.get("fromid").toString());
		this.setSname(map.get("fromid").toString());
		this.setPrTime(map.get("t_reporttime").toString());
		this.setContent(map.get("content").toString());
		this.setPresult(map.get("rpresult").toString());
		this.setIsAppend(map.get("isappend").toString());
		if (isAppend.equals("1")) {
			this.setAppendFile((Integer) map.get("t_reportid"));
		}
		this.setGrade(grade);
		this.setToID((Integer) map.get("t_reportid"));
		this.setToName(this.toName);
	}

	public List<String> getToName() {
		return toName;
	}

	public void setToName(List<String> toName) {
		this.toName = toName;
	}

	public List<String> getToID() {
		return toID;
	}

	public void setToID(int reportid) {
		String sql = "select * from taskmember where taskid = " + reportid;
		List<Map> list = new ArrayList<Map>();
		list = OperateDB.executeQuery(sql);
		
		this.toID = new ArrayList<String>();
		this.toName = new ArrayList<String>();
		if (list != null && list.size() > 0) {
			for (int i = 0; i < list.size(); i++) {
				Map map = list.get(i);
				String toid = (String) map.get("memberid");

				sql = "select * from stuinfo where sno = '" + toid + "' ";
				List<Map> list3 = new ArrayList<Map>();
				list3 = OperateDB.executeQuery(sql);
				if (list3 != null && list3.size() != 0) {// 是学生
					this.toID.add(toid);
					Map map3 = list3.get(0);
					String toname = (String) map3.get("sname") + ", ";
					this.toName.add(toname);
				} else {// 是老师
					sql = "select * from teacherinfo where tno = '" + toid
							+ "' ";
					List<Map> list2 = new ArrayList<Map>();
					list2 = OperateDB.executeQuery(sql);
					if (list2 != null && list2.size() > 0) {
						this.toID.add(toid);
						Map map2 = list2.get(0);
						String toname = (String) map2.get("tname") + "[老师],";
						this.toName.add(toname);
					}
				}

			}

		}

	}

	public String getFromName() {
		return fromName;
	}

	public void setFromName(String fromID) {
		String sql = "select * from teacherinfo where tno = '" + fromID + "' ";
		List<Map> list = new ArrayList<Map>();
		list = OperateDB.executeQuery(sql);
		if (list != null && list.size() != 0) {
			Map map = list.get(0);
			this.fromName = (String) map.get("tname");
			fromName += "[老师]";
		} else {
			sql = "select * from stuinfo where sno = '" + fromID + "' ";
			list = OperateDB.executeQuery(sql);
			if (list != null && list.size() != 0) {
				Map map = list.get(0);
				this.fromName = (String) map.get("sname");
			}
		}

	}

	public int getGrade() {
		return grade;
	}

	public void setGrade(int grade) {
		this.grade = grade;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public String getIsleaf() {
		return isleaf;
	}

	public void setIsleaf(String isleaf) {
		this.isleaf = isleaf;
	}

	public int getRootid() {
		return rootid;
	}

	public void setRootid(int rootid) {
		this.rootid = rootid;
	}

	public int getPid() {
		return pid;
	}

	public void setPid(int pid) {
		this.pid = pid;
	}

	public List<Map> getAppendFile() {
		return appendFile;
	}

	public void setAppendFile(int t_reportID) {
		String sql = "select * from appendinfo where append_type = '任务报告' "
				+ "and fileid = " + t_reportID;
		//System.out.println(sql);
		List<Map> list = new ArrayList<Map>();
		list = OperateDB.executeQuery(sql);
		if (list.size() > 0) {// 有附件时才初始化appendFile对象
			appendFile = new ArrayList<Map>();
			for (int i = 0; i < list.size(); i++) {
				Map map = list.get(i);
				String fileName = (String) map.get("filename");
				String saveName = (String) map.get("savename");
				Map<String, String> map2 = new HashMap<String, String>();
				map2.put("fileName", fileName);
				map2.put("saveName", saveName);
				appendFile.add(map2);
			}
		}
	}

	public String getSname() {
		return sname;
	}

	public void setSname(String userno) {
		String sql = "select sname from stuinfo where sno = '" + userno + "'";
		String name = "";
		List<Map> list = new ArrayList<Map>();

		list = OperateDB.executeQuery(sql);
		if (list.size() > 0) {
			Map map = list.get(0);
			name = (String) map.get("sname");
		}
		this.sname = name;
	}

	public int getPrID() {
		return prID;
	}

	public void setPrID(int prID) {
		this.prID = prID;
	}

	public int getTaskID() {
		System.out.println(taskID);
		return taskID;
	}

	public void setTaskID(int taskID) {
		this.taskID = taskID;
	}

	public String getFromID() {
		return fromID;
	}

	public void setFromID(String fromID) {
		this.fromID = fromID;
	}

	public String getPrTime() {
		return prTime;
	}

	public void setPrTime(String prTime) {
		this.prTime = prTime;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public String getPresult() {
		return presult;
	}

	public void setPresult(String presult) {
		this.presult = presult;
	}

	public String getIsAppend() {
		return isAppend;
	}

	public void setIsAppend(String isAppend) {
		this.isAppend = isAppend;
	}

}
